package com.Cychat.doctor.controller;

import com.Cychat.commons.entity.ResultMessage;
import com.Cychat.commons.entity.vo.AppointmentDetailVo;
import com.Cychat.doctor.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约记录Controller（医生专属）
 */
@RestController
@RequestMapping("/api/doctor/appointment")
public class AppointmentController {

    @Autowired
    private AppointmentService appointmentService;

    /**
     * 查询当前医生的所有预约记录（全量，前端处理分页搜索）
     * @param doctorId 医生ID（请求头）
     * @return 预约详情VO列表
     */
    @GetMapping("/list")
    public ResultMessage<List<AppointmentDetailVo>> getDoctorAppointmentList(@RequestHeader("doctorId") Integer doctorId) {
        List<AppointmentDetailVo> list = appointmentService.getDoctorAppointmentList(doctorId);
        return ResultMessage.success(list);
    }

    /**
     * 查询预约详情（含权限校验）
     * @param appointmentId 预约ID
     * @param doctorId 医生ID（请求头）
     * @return 预约详情VO
     */
    @GetMapping("/info/{appointmentId}")
    public ResultMessage<AppointmentDetailVo> getAppointmentDetail(
            @PathVariable("appointmentId") Integer appointmentId,
            @RequestHeader("doctorId") Integer doctorId
    ) {
        AppointmentDetailVo vo = appointmentService.getDoctorAppointmentDetail(appointmentId, doctorId);
        return vo != null ? ResultMessage.success(vo) : ResultMessage.error("预约记录不存在或无权限");
    }
}